package com.xxwy.spring.event;

import java.util.Observable;
import java.util.Observer;

/**
 * JDK9-Observable/Observer被推荐转换为java.util.concurrent.Flow实现
 *
 * @author xxwy
 * @date 2021/9/16 0016
 */
public class ObserverDemo {

    public static void main(String[] args) {
        EventObservable observable = new EventObservable();
        observable.addObserver(new EventObserver());
        observable.notifyObservers("hello world");
    }

    static class EventObservable extends Observable {

        @Override
        public void notifyObservers(Object arg) {
            super.setChanged();
            super.notifyObservers(arg);
            super.clearChanged();
        }
    }

    static class EventObserver implements Observer {

        @Override
        public void update(Observable o, Object arg) {
            System.out.println("收到参数： " + arg);
        }
    }
}
